package com.yn.demo_redis_lock.redis;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RedissonConfig
 * @Description:
 * @author: 王胜
 * @date 2021/4/13
 * @Version: 1.0
 **/
//@Configuration
public class RedissonConfig {

    @Bean
    public Redisson redisson(@Autowired RedisProperties redissonProperty) {
        String redisUrl = String.format("redis://%s:%s", redissonProperty.getHost() + "", redissonProperty.getPort() + "");
        Config config = new Config();
        config.useSingleServer().setAddress(redisUrl).setPassword(redissonProperty.getPassword());
        config.useSingleServer().setDatabase(redissonProperty.getDatabase());
        return (Redisson) Redisson.create(config);
    }

}
